package com.br4mmie.asciistory.mission;

import java.io.BufferedReader;
import java.io.IOException;

import com.br4mmie.asciistory.ASCIIStoryActivity;
import com.br4mmie.asciistory.CharImage;


public class ConsumableItem extends Item
{
	int healingAmount;
	
	public ConsumableItem(String name, int healAmount, String description, CharImage itemImage, int gold, String type) 
	{
		super(name, description, itemImage, gold, type);
		healingAmount = healAmount;
	}

	public boolean use()
	{
		ASCIIStoryActivity.getPlayer().currentHP += healingAmount;
		if (ASCIIStoryActivity.getPlayer().currentHP > ASCIIStoryActivity.getPlayer().maxHP) 
			ASCIIStoryActivity.getPlayer().currentHP = ASCIIStoryActivity.getPlayer().maxHP;
		
		return true;
	}
	
	public static ConsumableItem fromFile(String line, BufferedReader file) throws IOException
	{
		String name = line.substring(2);
		int a = 0;
		CharImage i = null;
		String z = null;
		int g = 0;
		String t = null;
		while (true)
		{
			line = file.readLine();
			if (line == null) break;
			
			if(line.startsWith("a "))//healamount
			{
				a = Integer.parseInt(line.substring(2));
			}
			else if(line.startsWith("i ")) //charimage
			{
				i = new CharImage(1, 1);
				i.setImage(line.substring(2));
			}
			else if(line.startsWith("z ")) //description
			{
				z = line.substring(2);
			}
			else if(line.startsWith("g ")) //price
			{
				g = Integer.parseInt(line.substring(2));
			}
			else if(line.startsWith("t ")); //type
			{
				t = line.substring(2);
			}
		}
		return new ConsumableItem(name, a, z, i, g, t);
	}
}
